package com.ewhale.feitengguest.presenter.user.mine;

import com.ewhale.feitengguest.api.ApiHelper;
import com.ewhale.feitengguest.dto.AuthInfoDto;
import com.ewhale.feitengguest.dto.BalanceDto;
import com.ewhale.feitengguest.dto.WalletLogDto;
import com.ewhale.feitengguest.view.user.mine.MyWalletView;
import com.ewhale.feitengguest.view.user.mine.UserInfoView;
import com.simga.library.base.IPresenter;
import com.simga.library.http.APIException;

import java.util.List;

public class MyWalletPresenter extends IPresenter {
    public void loadBalance() {
        mView.showProLoading();
        request(1, ApiHelper.USER_API.laodBalance(),null);
    }

    public void loadWallteLog(int pageNum) {
        mView.showProLoading();
        request(2, ApiHelper.USER_API.laodWalletLog(10,pageNum),pageNum);
    }

    public void loadAuthInfo() {
        mView.showProLoading();
        request(3, ApiHelper.USER_API.getAuthInfo(), null);
    }

    @Override
    public <T> void onNext(int postCode, T result, Object data) {
        super.onNext(postCode, result, data);
        switch (postCode){
            case 1:
                ((MyWalletView)mView).showBalance((BalanceDto)result);
                break;
            case 2:
                ((MyWalletView)mView).showWalletLog((List<WalletLogDto>)result,(int)data);
                break;
            case 3:
                ((MyWalletView) mView).showAuthInfo((AuthInfoDto) result);
                break;
        }
    }

    @Override
    public void otherException(int postCode, Object data, APIException e) {
        super.otherException(postCode, data, e);
        mView.showErrorMessage(postCode,e.getCode(),e.getDisplayMessage());
    }
}
